package com.bigflexlib.ds.op
{
	import flash.utils.Dictionary;
	
	import com.bigflexlib.ds.DataStructureEvent;
	import com.bigflexlib.ds.container.ContainerDiff;
	import com.bigflexlib.ds.container.IRContainer;
	import com.bigflexlib.ds.container.zet.IWSet;

	public class ContainerToSetOp extends AbstractContainerToSetOp
	{
		

		private var dict:Dictionary;

		
		public function ContainerToSetOp( iContainer:IRContainer, oSet:IWSet )
		{
			super( iContainer, oSet );

			dict = new Dictionary( );
			
			refresh( );

		}
		
		
		
		
		private function refresh( ):void
		{
		
			oSet.autoUpdateFlag.disable( );
		
			oSet.clear( );


			var added:Dictionary = new Dictionary( );


			iContainer.walk( 
			
				function( e:*, m:int ):void
				{

					if ( added[ e ] != true )
					{
						oSet.add( e );
						added[ e ] = true;
					}


				}
			
			);


		
			oSet.autoUpdateFlag.enable( );

		}
		
		
		
		override protected function iContainer_change( event:DataStructureEvent ):void
		{

			oSet.autoUpdateFlag.disable( );
		

			var diff:ContainerDiff = event.diff as ContainerDiff;
			
			diff.addedElements.walk( 
				function( e:*, m:int ):void
				{
					oSet.add( e );
				}
			);			


			diff.removedElements.walk( 
				function( e:*, m:int ):void
				{
					oSet.remove( e );
				}
			);			
		
		
			oSet.autoUpdateFlag.enable( );

		}
				
		
		
		
	}
}